package bsh.compilation;

public class ArrayTest2 extends AbstractCompilationTestCase {

    public void testLength() {
        String[] array = new String[]{ "test", "test0" };
        fields.put("object", array);
        Object r = execute("return object.length;");
        assertEquals(Integer.valueOf(2), r);
    }

    public void testLengthDynamic() {
        Object r = execute("Object a = new String[]{}; return a.length;");
        assertEquals(Integer.valueOf(0), r);
    }
    
    public void testAccessElement() {
        String[] array = new String[]{ "test", "test0" };
        fields.put("array", array);
        Object r = execute("array[0]");
        assertEquals("test", r);
    }
    
    public void testArrayOfArrays() {
        Object r = execute("Object[][] a = new Object[][]{ new Object[]{1}  }; a[0][0]");
        assertEquals(1, r);
    }
    
    public void testNewArray() {
        Object r = execute("new Object[10][12]");
        assertTrue(r instanceof Object[]);
    }

    public void testArrayAccess() throws Exception {
        Object r = executeClasspathResource("/arrayaccess.bsh");
        assertEquals(r, "someString10");
    }
    
}
